package com.sto.stoapp.activity.administrator.system;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.broadcast.HomeBroadAction;
import com.sto.stoapp.db.StoFilePreference;
import com.sto.stoapp.util.Helper;
import com.sto.stoapp.widget.StoHhmEditText;
import com.sto.stoapp.widget.StoHomeActivity;

/**
 * Created by wj on 2017-01-03.
 *
 * 蓝牙称重最大重量设置页面
 */

public class SettingBlueWeightActivity extends StoHomeActivity {

    private StoHhmEditText scanTimeEdit;

    private Button save;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting_blue_weight);

        String broadType = getIntent().getStringExtra(
                HomeBroadAction.BROAD_TYPE);
        // 判断是管理员的系统设置还是业务内部的系统设置
        if (broadType != null && !broadType.equals("")) {
            this.setTitleBottom(R.string.blue_weight_setting, broadType);
        } else {
            this.setTitleBottom(R.string.blue_weight_setting,
                    HomeBroadAction.ADMINISTRATOR_BROAD);
        }

        scanTimeEdit = (StoHhmEditText) findViewById(R.id.scan_time_edit);
        save = (Button) findViewById(R.id.scan_save);

        scanTimeEdit.setText(""
                + StoFilePreference.getInstance(this).getBlueWeight());

        save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String weight=scanTimeEdit.getText().toString().trim();
                if(TextUtils.isEmpty(weight)){
                    Helper.showToast(SettingBlueWeightActivity.this, "蓝牙重量不能为空");
                    return;
                }else if(Float.valueOf(weight)>500f){
                    Helper.showToast(SettingBlueWeightActivity.this, "蓝牙重量最大500KG");
                    return;
                }else {
                    setBlueWeight(Float.valueOf(weight));
                }
            }
        });
    }

    /**
     * 设置扫描头时间
     *
     * @param
     */
    private void setBlueWeight(float weight) {
        StoFilePreference.getInstance(this).setBlueWeight(weight);
        Helper.showToast(SettingBlueWeightActivity.this, getText(R.string.set_success)
                .toString());
        finish();
    }
}
